package rgs.sphere.jdbc.algorithm;

import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;

import java.util.Arrays;
import java.util.Collection;

/**
 * @program: rgs-study0project
 * @description: 数据表范围查询分片策略
 * @author: Mr.Ren
 * @create: 2023-11-12 21:19
 **/
public class MyTableRangeAlgorithm implements RangeShardingAlgorithm<Long> {

    @Override
    public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {
        // sql select * from product where cid between 1 and 100
        Long upper = rangeShardingValue.getValueRange().upperEndpoint();
        Long lower = rangeShardingValue.getValueRange().lowerEndpoint();

        String logicTableName = rangeShardingValue.getLogicTableName();

        //将两个数据表都返回出去，表示，两个表中都需要执行这条范围查询语句
        return Arrays.asList(logicTableName+"_1",logicTableName+"_2");
    }
}

